export BUILD_TOPDIR=$(PWD)
export STAGING_DIR=$(BUILD_TOPDIR)/tmp
export TOPDIR=$(PWD)
export UBOOTDIR=$(TOPDIR)/u-boot_mr1750

### Toolchain config ###
#buildroot
CONFIG_TOOLCHAIN_PREFIX=/root/lede-sdk-gcc-5.4.0/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin/mips-openwrt-linux-

export CROSS_COMPILE=$(CONFIG_TOOLCHAIN_PREFIX)
export MAKECMD=make ARCH=mips

export UBOOT_GCC_4_3_3_EXTRA_CFLAGS=-fPIC

export COMPRESSED_UBOOT=0

ifeq ($(BOARD_TYPE),mr1750)
export UBOOT_CONFIG_TARGET=board955x
export BOARD_NAME=OM5P-ACv2
export CFG_BOARD_TYPE=ap135
export CONFIG_SKIP_LOWLEVEL_INIT=1
export ETH_CONFIG2=_ar8033
export CONFIG_OM5PACV2_UNLOCKER=1
export FLASH_SIZE=16
endif

TARGETS=mr1750

IMAGEPATH=$(BUILD_TOPDIR)/output
UBOOT_BINARY=u-boot.bin
UBOOTFILE=$(BOARD_TYPE)_u-boot.bin

all:
ifeq (,$(filter $(BOARD_TYPE), $(TARGETS)))
	@echo "Run 'make BOARD_TYPE=<target_name>'"
	@echo "Available targets: $(TARGETS)"
else
	cd $(UBOOTDIR) && $(MAKECMD) $(UBOOT_CONFIG_TARGET)_config
	cd $(UBOOTDIR) && $(MAKECMD)
	@echo Copy binaries to $(IMAGEPATH)/$(UBOOTFILE)
#	mkdir -p $(IMAGEPATH)
	cp -f $(UBOOTDIR)/$(UBOOT_BINARY) $(IMAGEPATH)/$(UBOOTFILE)
	@make clean
	@echo Done
endif
	
clean:
	cd $(UBOOTDIR) && $(MAKECMD) distclean